'use strict';
const db = uniCloud.database();
const dbCollectionName = 'zhy_user_withdrawal_record';
exports.main = async (event, context) => {
	//event为客户端上传的参数
	console.log('event : ', event)
	if (objIsEmpty(event) || objIsEmpty(event.operateType)) {
		console.log('参数不齐');
		return null
	}
	if (event.operateType == 1) {
		// add
		return addWithdrawRecord(event, context)
	}
	//返回数据给客户端
	return event
};
async function addWithdrawRecord(event, context) {
	let {
		operateType,
		type,
		...data
	} = event
	return await db.collection(dbCollectionName).add(data)
}

function objIsEmpty(obj) {
	if (obj == undefined || obj == '' || obj == null || JSON.stringify(obj) == '{}') {
		return true
	}
	return false
}